package com.example.shop_2304.adapter

import android.graphics.Color
import android.widget.LinearLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.ExplosiveMoney
import com.example.shop_2304.R

class TypeAdapter:BaseQuickAdapter<ExplosiveMoney,BaseViewHolder>(R.layout.item_type) {
    var selectedType = 4//默认选中的是第一个 有背景色
    override fun convert(holder: BaseViewHolder, item: ExplosiveMoney) {
        holder.setText(R.id.type_info,item.info)
        holder.setText(R.id.type_name,item.name)
        if(selectedType==item.type.toInt()){
            //选中为红色背景
            holder.getView<LinearLayout>(R.id.ll_type).setBackgroundResource(R.drawable.bg_selected)
        }else{
            //未选中为白色背景
            holder.getView<LinearLayout>(R.id.ll_type).background = null
        }

    }

    //设置点击修改选中值的方法
    fun setType(type:Int){
        selectedType = type
        notifyDataSetChanged()//刷新后，背景色才会发生变化
    }
}